package olive.mycourse.users;

import java.util.Scanner;

public class User
{
    private String userName;
    private int id;
    private String password; //a four digit number.

    public User()
    {
        userName = "N/A";
        id = 00000;
        password = "123456";
    }


    public User(String userName, int id, String password)
    {
        setUser(userName, id, password);
    }

    public User(int id)
    {
        setUser("N/A", id, "123456");
    }

    public User(User aUser)
    {
        if (aUser == null)//Not a real date.
        {
             System.out.println("Fatal Error.");
             System.exit(0);
        }

        userName = aUser.userName;
        id = aUser.id;
        password = aUser.password;
    }



    public void setUser(String userName, int id, String password)
    {

            this.userName = userName;
            this.id = id;
            this.password = password;

    }

    public void setUser(int id)
    {
        setUser("N/A", id, "123456");
    }

    public void setPassword(String password)
    {

            this.password = password;
    }
    public void setUserName(String userName)
    {
    	this.userName = userName;
    }

    public void setId(int id)
    {
        if ((id <= 0) || (id > 99999))
        {
            System.out.println("Invalid id");
            System.exit(0);
        }
        else
            this.id = id;
    }

    public String getUserName( )
    {
    	return userName;
    }

    public int getId( )
    {
        return id;
    }

    public String getPassword( )
    {
        return password;
    }

    public String toString( )
    {
        return ("user name:" + userName + " id:" + id + " password:" + password);
    }

    public boolean equals(User otherUser)
	{
	    if (otherUser == null)
	        return false;
	    else
	        return (id == otherUser.id);
    }


//here provide a god mode to input a user
    public void readInput( )
    {
        boolean tryAgain = true;
        Scanner keyboard = new Scanner(System.in);
        while (tryAgain)
        {
            System.out.println("Enter userName, id, and password:");
              System.out.println("Do not use a comma.");
            String userNameInput = keyboard.next( );
            int idInput = keyboard.nextInt( );
            String passwordInput = keyboard.next( );
                setUser(userNameInput, idInput, passwordInput);
                tryAgain = false;
         }
    }


}
